class NameAlias < ActiveRecord::Base
  #relations
  belongs_to		:artist

  #Callbacks
  after_update :create_edit
  after_create :new_entry_edit

  #Validations
  validates_presence_of :artist
  validates_presence_of :name

  private

  def new_entry_edit
    entry = Hash.new
    entry.store("add alias", [self.name, self.artist.name])
    Edit.create_edit(entry, self.artist)
  end

  def create_edit
    if self.changed?
      entry = Hash.new
      entry.store("alias", self.changes.fetch("name"))
      Edit.create_edit(entry, self.artist)
    end
  end
end
